package cn.tedu.spring.life;
/**
 * Bean对象的生命周期:
 *  1.实例化：无参构造;
 *  2.属性赋值：set方法;
 *  3.初始化：@PostConnect
 *  4.开发者使用;
 *  5.销毁@PreDestory
 */
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class DBConnect {
    private String username;

    public DBConnect(){
        System.out.println("1-调用无参构造实例化;");
    }

    @Value("叶辰")
    public void setUsername(String username) {
        this.username = username;
        System.out.println("2-调用set方法给属性赋值;");
    }
    @PostConstruct
    public void init(){
        System.out.println("3-执行生命周期初始化的方法;");
    }
    @PreDestroy
    public void destroy(){
        System.out.println("5-执行生命周期销毁方法;");
    }
}
